<?php

/**
 * @property CI_Loader $load
 * @property CI_Form_validation $form_validation
 * @property CI_Input $input
 * @property CI_Email $email
 * @property CI_DB_active_record $db
 *
 */
class Statistics extends CI_Controller {

    function __construct() {
        parent::__construct();
        // $this->load->helper('form');
    }

    function index() {
        $this->entrance();
        $data["title"] = "Statistics";
        $data["content"] = "statistics/content";
        $data["sidebar"] = "statistics/sidebar";
        $this->db->query("call statistics()");
        $this->load->model('Stat');
        $data["year"] = $this->Stat->get_year();
        $js[] = "statistics.js";
        $js[] = "jquery.validate.js";
        $js[] = "jquery.jqplot.min.js";
        $js[] = "jqplot.barRenderer.min.js";
        $js[] = "jqplot.categoryAxisRenderer.min.js";
        $js[] = "jqplot.pointLabels.min.js";

        $data["js"] = $js;
        $this->load->model('Exchange');
        $data["exchange"] = $this->Exchange->exchange_list();
        $this->load->view("template", $data);
    }

    function entrance() {

        if ($this->session->userdata('logged_in') != null && $this->session->userdata('rank') == 'Director') { {
                $this->id = $this->session->userdata('id');
                return 1;
            }
        } else {
            redirect('admin');
        }
    }

    function get_data_ajax() {
        $this->entrance();
        $this->load->model('Stat');
        $code = $_POST["code"];
        if (isset($_POST["year"])) {
            $year = $_POST["year"];
            $month = $_POST["month"];
            $data = $this->Stat->get_stat2($year, $month, $code);
            $data['month'] = $this->Stat->get_max_month($year);
        } else {
            $data = $this->Stat->get_stat($code);
        }
        echo json_encode($data);
    }

}